// akslideshow- jQuery plugin from adaption of JonDesign's SmoothSlideshow
// http://www.amiwork.co.in/talk
// Copyright (c) 2008 Amit Kumar Singh
// http://www.gnu.org/licenses/gpl.html

(function($){
	//code goes here
	$.fn.initSlideShow=function(data){
		
		var settings=data
		
		return this.each( function(){
			settings.totalSlides=settings.img.length;
			settings.currentSlide=-1;
			//alert(this);
			$(this).html('');
			div=this;
			settings.obj=$(div);
			$.each(settings.img,function(key,value){
				//for each image create a div with img tag and place for title	
				slide=makeSlide(key,value,settings.cap[key],settings.title[key]);
				$(div).append(slide);
			});
			startSlideShow(div);
			
			function makeSlide(key,src,cap,title){
				str="<div class='img_holder' "+" id='slide_"+key+"' style='visibility:visible;position:absolute;'>";
				str=str+"<img src='"+src+"' border=0>";
				str=str+"<div id='slide_"+key+"_info'>";	
				str=str+"<h2 class='title'>"+title+"</h2>";
				str=str+"<p>"+cap+"</p>";
				str=str+"</div>";
				str=str+"</div>";
				return str;
			};
			
			function showNextSlide(obj)
			{
				$.each(obj.children(),function(){
					$(this).css('visibility','hidden');
					$('#'+$(this).attr('id')+'_info').fadeTo('fast',.8); 
					
				});
				
				settings.currentSlide=settings.currentSlide+1;
				$("#slide_"+settings.currentSlide).css('visibility','visible');
				$("#slide_"+settings.currentSlide+"_info").fadeTo('fast',.5);
				if(settings.currentSlide==(settings.totalSlides-1))
					settings.currentSlide=-1;
			};
			function startSlideShow()
			{
				showNextSlide(settings.obj);
				setTimeout(startSlideShow,2000);
			};
			
			
		});
	};

})(jQuery);